Page({
  data: {
    userInfo: {
      avatarUrl: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0',
      nickName: '管理员'
    },
    greeting: '早上好',
    currentTab: 'dashboard',
    statistics: {
      totalGeese: 2580,
      todayEggs: 386,
      todayDeath: 2,
      todayNew: 150
    },
    quickActions: [
      { id: 1, name: '添加大鹅', icon: 'icon-add-goose' },
      { id: 2, name: '健康记录', icon: 'icon-health' },
      { id: 3, name: '饲料管理', icon: 'icon-feed' },
      { id: 4, name: '产蛋记录', icon: 'icon-egg' },
      { id: 5, name: '疫苗接种', icon: 'icon-vaccine' },
      { id: 6, name: '销售记录', icon: 'icon-sales' },
      { id: 7, name: '成本统计', icon: 'icon-cost' },
      { id: 8, name: '环境监测', icon: 'icon-monitor' }
    ],
    adminActions: [
      { id: 1, name: '用户管理', icon: 'icon-users-manage' },
      { id: 2, name: '系统设置', icon: 'icon-system' }
    ],
    notices: [
      {
        id: 1,
        content: '关于系统维护更新的通知',
        time: '12-20'
      },
      {
        id: 2,
        content: '请及时完成今日的养殖数据录入工作',
        time: '12-20'
      },
      {
        id: 3,
        content: '新版本功能更新说明',
        time: '12-19'
      }
    ]
  },
  
  onLoad() {
    this.getStatistics()
    this.setGreeting()
    
    const app = getApp()
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo
      })
    }
  },

  setGreeting() {
    const hour = new Date().getHours()
    let greeting = '早上好'
    if (hour >= 12 && hour < 18) {
      greeting = '下午好'
    } else if (hour >= 18) {
      greeting = '晚上好'
    }
    this.setData({ greeting })
  },

  getStatistics() {
    // 这里添加获取统计数据的接口请求
  },

  switchTab(e) {
    const tab = e.currentTarget.dataset.tab
    this.setData({ currentTab: tab })
    
    // 根据tab进行页面跳转
    switch(tab) {
      case 'user':
        wx.navigateTo({
          url: '/pages/user/user'
        })
        break
      case 'settings':
        // 设置页面跳转（如果有的话）
        wx.navigateTo({
          url: '/pages/settings/settings'
        })
        break
      case 'dashboard':
        // 如果已经在首页，不需要跳转
        break
    }
  },

  onActionTap(e) {
    const actionId = e.currentTarget.dataset.id
    // 处理快捷功能点击事件
    switch(actionId) {
      case 9: // 管理员功能
        wx.navigateTo({
          url: '/pages/admin/admin'
        })
        break
      default:
        console.log('点击了快捷功能:', actionId)
    }
  },

  onAdminActionTap(e) {
    const actionId = e.currentTarget.dataset.id
    switch(actionId) {
      case 1:
        wx.navigateTo({ url: '/pages/admin/users/users' })
        break
      case 2:
        wx.navigateTo({ url: '/pages/admin/settings/settings' })
        break
    }
  },

  // 查看更多公告
  viewMoreNotices() {
    wx.navigateTo({
      url: '/pages/notices/notices'
    })
  },

  // 查看公告详情
  viewNoticeDetail(e) {
    const noticeId = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/notices/detail?id=${noticeId}`
    })
  }
}) 